<?php

namespace catchAdmin\phone\model;

class SysLabel extends \catchAdmin\model\SysLabel
{

    ######################################## 显示 ################################################

    public function indexData($param)
    {
        $company_type = $this->getLoginUser()['company_type'];

        $table_list_2 = [];
        if (!empty($param['company_type'])) {
            $company_type = $param['company_type'];
            $table_list_2 = $param['sys_label_id'] ?? [];
        } else {
            $table_list = (new \catchAdmin\model\SysLabelUser())
                ->where('wechat_user_id', $this->getLoginId())
                ->select()
                ->toArray();
            foreach ($table_list as $k => $v) {
                $table_list_2[$v['sys_label_id']] = $v['sys_label_id'];
            }
        }

        $list = $this
            ->where('company_type', $company_type)
            ->order('id', 'asc')
            ->select()
            ->toArray();

        $list_2 = [];
        foreach ($list as $k => $v) {
            $v['selected'] = false;
            if (in_array($v['id'], $table_list_2)) {
                $v['selected'] = true;
            }

            $key = 'short';
            if (mb_strlen($v['label_name']) > 4) {
                $key = 'long';
            }

            $list_2[$key][] = $v;
        }

        return $list_2;
    }


    public function indexZhaoPin($param)
    {
        return $this
            ->where('company_type', 100)
            ->select()
            ->toArray();
    }


}
